<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>对数组进行代理截取标题操作</title>
  </head>
  <body></body>
  <script>
    "use strict";
    const lessons = [
      {
        title: "媒体查询响应式布局",
        category: "css"
      },
      {
        title: "FLEX 弹性盒模型",
        category: "css"
      },
      {
        title: "MYSQL多表查询随意操作",
        category: "mysql"
      }
    ];
    let proxy = new Proxy(lessons, {
      get(arr, key) {
        const title = arr[key].title;
        const len = 10;
        arr[key].title =
          title.length > len ? title.substr(0, len) + ".".repeat(3) : title;
        return arr[key];
      }
    });
    console.log(JSON.stringify(proxy[2], null, 2));
  </script>
</html>
